% File:        toaster_model_update
% Author:      M. P. Hayes UC ECE
% Date:        1 October 2007

function model = toaster_model_update (model, p, T_a)
%
% model = toaster_model_update (model, p, T_a)
%
% Update the toaster model, where:
%  model   is a model structure
%  p       is the current heater power (W)
%  T_a     is the ambient temperature (C)  
%
% Note the ambient temperature is assumed constant and is currently ignored.
%  
% See also toaster_model_temp and toaster_model_init.

% File:        toaster_model_init.m
% Author:      M. P. Hayes UC ECE
% Date:        1 October 2007  
  
  % Update the heater power history.
  model.p = [p; model.p(1:end-1)];

  model.n = model.n + 1;
  if model.n < numel (model.i)
    T_a = model.i(model.n);
  else
    T_a = model.i(end);
  end
  
  
  % Convolve impulse update with previous excitation but only
  % consider result at zero lag.
  model.T = sum (model.p .* model.h) * model.delta_t + T_a;
